from appium import webdriver
from appium.options.android import UiAutomator2Options

capabilities = {
    "platformName": "Android",
    "deviceName": "emulator-5554",
    "appPackage": "com.android.settings",
    "appActivity": "com.android.settings.Settings",
    "automationName": "UiAutomator2",
    "noReset": True  # 关键：添加此配置，避免重新安装应用
}
options = UiAutomator2Options().load_capabilities(capabilities)

driver = webdriver.Remote(
    command_executor='http://localhost:4723',  # 注意路径简化
    options=options
)

try:
    #执行操作（示例）
    print("ok")
    #截图
    # Appium 截图示例（关键代码是否存在）
    driver.save_screenshot('tu.png')
    #driver.find_element(by='id', value='digit_2').click()
    #driver.find_element(By.ACCESSIBILITY_ID, "2").click()
finally:
    driver.quit()